﻿using Max.PH5_2004A.Shopping.Domain;
using Max.PH5_2004A.Shopping.DTO.Goods;
using Max.PH5_2004A.Shopping.IRespository;
using Max.PH5_2004A.Shopping.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH5_2004A.Shopping.Service
{
    public class CategoryService : BaseService<CategoryModel>, ICategoryService
    {
        ICategoryRespository _respository;
        public CategoryService(ICategoryRespository respository) : base(respository)
        {
            _respository = respository;
        }

        public List<CategoryDto> GetCategory(int id)
        {
            var a = _respository.Select().ToList();

            var list = a.Where(x => x.PId == id).ToList();

            List<CategoryDto> dtos = new List<CategoryDto>();
            foreach (var item in list)
            {
                CategoryDto dto = new CategoryDto
                {
                    PId = item.PId,
                    Name = item.Name,
                    Id = item.Id,
                    Children = GetCategory(item.Id)
                };
                dtos.Add(dto);

            }
            return dtos;
        }
    }
}
